<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :showAttrs="showAttrs"
    >
      <template v-slot:header>
        <el-button size="small" type="warning" @click="openChartDialog">图表</el-button>
      </template>
    </table-view>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <ingredient-info-add-or-update v-if="ingredientInfoVisible" ref="ingredientinfo"></ingredient-info-add-or-update>
    <!--  图表对话框  -->
    <normal-chart-dialog ref="charDialog"
                         :chartTypes="chartTypes"
                         :chartSearchObj="chartSearchObj"
                         :commitChartSearch="commitChartSearch"
    >
      <template v-slot:chart="{chart}">
        <line-chart v-if="R.equals('line', chart.chartType)" ref="chart"></line-chart>
        <pie-chart v-if="R.equals('pie', chart.chartType)" ref="chart"></pie-chart>
      </template>
    </normal-chart-dialog>
  </div>
</template>

<script>
import AddOrUpdate from './ingredientadd-add-or-update'
import IngredientInfoAddOrUpdate from '@/views/modules/ingredient/ingredientinfo-add-or-update'
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import lineChart from '@/views/charts/ingredient/ingredientAddLineChart'
import pieChart from '@/views/charts/ingredient/ingredientAddPieChart'

export default {
  mixins: [basicMixins],
  data() {
    return {
      chartTypes: [
        {label: 'pie', text: '饼状图'},
        {label: 'line', text: '折线图'}
      ],
      chartSearchObj: {
        dataForm: {
          dateTimeRange: []
        },
        config: {
          dateTimeRange: {
            type: 'date',
            clearable: true,
            dateType: 'daterange',
            label: '时间范围'
          }
        }
      },
      searchAttrs: {
        ingredientInfoId: {
          type: 'autoComplete',
          placeholder: '辅料名称',
          querySearchApiName: 'ingredientApi/getIngredientInfoList'
        },
        plateNumber: {
          label: '车牌号',
          placeholder: '请输入车牌'
        },
        tickerNumber: {
          label: '票号',
          placeholder: '请输入票号'
        }
      },
      ingredientInfoVisible: false,
      primaryKey: 'id',
      listApiName: 'ingredientApi/listIngredientAddList',
      deleteApiName: 'ingredientApi/deleteIngredientAdd',
      saveAuthName: 'ingredient:ingredientadd:save',
      deleteAuthName: 'ingredient:ingredientadd:delete',
      showAttrs: {
        ingredientInfoName: {label: '原料名称'},
        weight: {label: '吨数'},
        price: {label: '价格'},
        tickerNumber: {label: '票号'},
        dayTime: {label: '日期', type: 'date'},
        plateNumber: {label: '车牌号'},
        freight: {label: '运费'},
        imageUrl: {label: '图片', type: 'image'},
        isPay: {
          label: '付款状态',
          type: 'radio',
          items: [
            {value: 0, text: '未付款', tagType: 'danger'},
            {value: 1, text: '已付款'}
          ]
        },
        status: {
          label: '状态',
          type: 'radio',
          items: [
            {value: 0, text: '禁用', tagType: 'danger'},
            {value: 1, text: '正常'}
          ]
        }
      }
    }
  },
  methods: {
    openIngredientInfoDialog(cb) {
      this.ingredientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.ingredientinfo)) {
          this.$refs.ingredientinfo.init(null, {status: 1}, cb)
        }
      })
    }
  },
  components: {
    IngredientInfoAddOrUpdate,
    tableView,
    AddOrUpdate,
    lineChart,
    pieChart
  }
}
</script>
